
"""
    多线程之间共享变量
"""
import threading
import time
num = 0


def work1():

    global num
    for i in range(1000000):
        num += 1

    print("work1----", num)


def work2():
    global num
    for i in range(1000000):
        num += 1

    print("work2----", num)


if __name__ == '__main__':

    thread1 = threading.Thread(target=work1)
    thread2 = threading.Thread(target=work2)

    thread1.start()
    # 优先让thread1先执行，thread1执行完毕之后，thread2才开始执行
    thread1.join()
    thread2.start()

    while len(threading.enumerate()) != 1:
        time.sleep(1)

    print("num = %d" % num)

